<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>跟进新客户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="css/layuimini.css">
    <link rel="stylesheet" href="css/public.css" media="all">
</head>
<body>
<div class="layuimini-container ">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>输入客户跟进状态信息</legend>
        </fieldset>
        <form class="layui-form" action="">

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">客户名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="custName" name="custName" required lay-verify="required"
                               placeholder="请选择"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">客户ID</label>
                    <div class="layui-input-block">
                        <input type="text" id="custId" name="custId" placeholder="" autocomplete="off"
                               class="layui-input" readonly="readonly">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">联系人</label>
                    <div class="layui-input-block">
                        <input type="text" id="custLinkman" name="custLinkman" placeholder="" autocomplete="off"
                               class="layui-input" >
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">负责人ID</label>
                    <div class="layui-input-block">
                        <input type="text" id="custUserId" name="custUserId" placeholder="" autocomplete="off"
                               class="layui-input" onkeyup="this.value=this.value.replace(/\D/g,'')"
                               onafterpaste="this.value=this.value.replace(/\D/g,'')">
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">客户状态</label>
                <div class="layui-input-block">
                    <select id="custStatus" name="custStatus">
                        <option value=""></option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">商机状态</label>
                <div class="layui-input-block">
                    <select id="businessStatus" name="businessStatus">
                        <option value=""></option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">客户性质</label>
                <div class="layui-input-block">
                    <select id="custProperty" name="custProperty">
                        <option value=""></option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item ">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="followForm">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="lib/layui-v2.5.5/layui.all.js" charset="utf-8"></script>
<script src="js/lay-module/tableSelect/tableSelect.js"></script>
<script>
    layui.use('form', function () {
        var form = layui.form;
        //form.render();
        var tableSelect = layui.tableSelect;
        var $ = layui.jquery;
        <!--表单下拉选择-->
        $.ajax({
            url: "getFollowDict",
            type: "GET",
            datatype: "json",
            success: function (result) {
                //console.log(result);   //{custIndustry: {…}, custLevel: {…}, custSource: {…}}
                for (var p in result) {
                    //console.log(p);  //p的值为custSource，result[p]为custSource的对应json字符窜
                    var type = result[p];
                    var custType = document.getElementById(p); //server为select定义的id，p："custIndustry"
                    for (var id in type) {
                        //console.log(result[p]);  //{1: "教育培训 ", 2: "电子商务", 3: "对外贸易", 4: "酒店旅游", 5: "房地产"}
                        //console.log(id);       //id
                        //console.log(type[id]);//值
                        var option = document.createElement("option");  // 创建添加option属性
                        option.setAttribute("value", id); // 给option的value添加值
                        option.innerText = type[id];     // 打印option对应的纯文本
                        custType.appendChild(option);           //给select添加option子标签
                        form.render("select");            // 刷性select，显示出数据
                    }
                }
                if(getQueryString('custId')!=null){
                    var id = getQueryString('custId');
                    $.ajax({
                        type:"post",
                        url:"editFollowStatus",
                        data:{"id":id},
                        success:function (data) {
                            console.log(data)
                            $("#custId").val(data.custId);
                            $("#custName").val(data.custName);
                            $("#custUserId").val(data.custUserId);
                            $("#custStatus").val(data.custStatus);
                            $("#businessStatus").val(data.businessStatus);
                            $("#custLinkman").val(data.custLinkman);
                            $("#custProperty").val(data.custProperty);
                            form.render();
                        }
                    })
                }
            }
        });
        tableSelect.render({
            elem: '#custName',
            checkedKey: 'id',
            searchKey: 'custName',	//搜索输入框的name值 默认keyword
            searchPlaceholder: '客户名搜索',	//搜索输入框的提示文字 默认关键词搜索
            table: {
                url: 'customerList',
                request: {
                    pageName: 'page', //页码的参数名称，默认：pageNum
                    limitName: 'pageSize' //每页数据量的参数名，默认：pageSize
                },
                parseData: function (res) { //res 即为原始返回的数据
                    //res.code=0;
                    console.log(res);
                    return {
                        "code": 0, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.total, //解析数据长度
                        "data": res.rows //解析数据列表
                    };
                },
                cols: [
                    [
                        {type: 'radio'},
                        {field: 'custId', title: 'ID'},
                        {field: 'custName', title: '客户名'},
                        {field: 'custLinkman', title: '联系人'},
                        {field: "custUserId", title: '负责人'}
                    ]
                ]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.custName);
                    $("#custId").val(item.custId);
                    $("#custUserId").val(item.custUserId);
                    $("#custLinkman").val(item.custLinkman)
                });
                elem.val(NEWJSON.join(","))
            }
        });
        form.on("submit(followForm)",function (data) {
            //console.log(data);
            layer.confirm("是否提交",function () {
                $.ajax({
                    url: "saveFollowStatus",
                    data: data.field,
                    //dataType: 'JSON',
                    type: 'post',
                    success: function (data) {
                        //console.log(data.msg);
                        layer.msg(data.msg,  {
                            icon: 1,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        },  function () {
                            //layer.closeAll();
                            parent.layer.close(parent.layer.index);
                            parent.layui.table.reload('currentTableId',{});
                        })
                    }
                });
            });

            return false;
        });

        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            //if (r != null) return unescape(r[2]);
            if (r != null) return decodeURI(r[2]);
            return null;
        }
    });
</script>
</body>
</html>
